# Contributor: Celeste <cielesti@protonmail.com>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=lemmy
pkgver=0.19.1
# this needs to be synced with lemmy-ui
_translations_commit=15815aea74fe97360afc03496b3ad62588649af0
pkgrel=0
pkgdesc="Link aggregator and forum for the Fediverse - Backend server"
url="https://join-lemmy.org/"
# armhf, armv7: fatal runtime error while compiling lemmy_server crate
# ppc64le, riscv64, s390x: ring crate
# x86: follow lemmy-ui aport
arch="aarch64 x86_64"
license="AGPL-3.0-only"
depends="postgresql-contrib" # pgcrypto
makedepends="
	cargo
	cargo-auditable
	libpq-dev
	openssl-dev
	"
install="$pkgname.pre-install $pkgname.post-install"
pkgusers="lemmy"
pkggroups="lemmy"
subpackages="$pkgname-openrc"
source="https://github.com/LemmyNet/lemmy/archive/$pkgver/lemmy-$pkgver.tar.gz
	https://github.com/LemmyNet/lemmy-translations/archive/$_translations_commit/lemmy-translations-$pkgver.tar.gz
	fix-db-init-script.patch
	lemmy.initd
	"
options="!check" # fails to load settings file as it is not found

# html2md required by lemmy_apub fails to build with panic=abort
export CARGO_PROFILE_RELEASE_PANIC="unwind"

prepare() {
	default_prepare

	rmdir -v crates/utils/translations
	ln -sv "$srcdir/lemmy-translations-$_translations_commit" \
		crates/utils/translations

	sed -i "s/unknown version/$pkgver/" crates/utils/src/version.rs
	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --frozen --release
}

check() {
	cargo test --frozen
}

package() {
	install -Dm755 target/release/lemmy_server -t "$pkgdir"/usr/bin
	install -Dm640 -g lemmy config/defaults.hjson \
		"$pkgdir"/etc/lemmy/lemmy.hjson

	install -Dm755 scripts/db-init.sh -t "$pkgdir"/usr/lib/$pkgname
	install -Dm755 "$srcdir"/lemmy.initd "$pkgdir"/etc/init.d/lemmy
}

sha512sums="
5386f4efbe9edfd695505e444d73a3dcea16de1204a1bc63e9bb4569189909c251ce3c22f24b430a43002d7540996d321f9cc2ff479642d6c00f8219a5672aec  lemmy-0.19.1.tar.gz
561e0cebc6958b527df50cd19d6b105e2dddada2591977b9c6c091b8397383a56e43db60bffafd06a28f56cc95c0a55d06b46c21ad00bd73be5a59e97503b953  lemmy-translations-0.19.1.tar.gz
fcfb3881abf8ee671bb55e47c71fef8ef1328a04b3278fd9602478260b0de0bdb55b27c1f6127e9729a65e3fc05cbcd245bd1f98b93ea307755ff748a68d770d  fix-db-init-script.patch
38858d181c0cc3073c56963be1043b1da2d6ca2ae5683feead1154e345b29b0a73b3a86b17c29927749500240775c53bca92c28cb49ce9f5b778e4b4e8ebb87a  lemmy.initd
"
